package com.wn.cloud.provider.controller;

import cn.hutool.core.lang.UUID;
import com.wn.cloud.common.constant.ResponseEnum;
import com.wn.cloud.common.entity.Payment;
import com.wn.cloud.common.response.CommonResult;
import com.wn.cloud.common.response.DataResult;
import com.wn.cloud.provider.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @FileName: PayMentController
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2020/3/7 - 23:38
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/{id}")
    public CommonResult getOne(@PathVariable("id") long id) {
        log.info(serverPort + "端口提供了服务");

        Payment payment = new Payment(id, serverPort + ": " + UUID.randomUUID());
        return DataResult.genDataResult(ResponseEnum.SUCCESS, payment);
    }

    @PostMapping
    public CommonResult save(@RequestBody Payment payment) {
        boolean flag = paymentService.save(payment);
        if (flag) {
            return CommonResult.genMessageResult(ResponseEnum.SUCCESS);
        }
        return CommonResult.genMessageResult(ResponseEnum.UNKNOWN_EXCEPTION);
    }
}
